import { Entity, Column, Index } from 'typeorm';
import { BaseEntity } from '../common/base/base.entity';

@Entity('email_logs')
@Index('idx_to_email', ['toEmail'])
export class EmailLog extends BaseEntity {
  @Column({
    type: 'bigint',
    nullable: true,
    comment: '用户ID',
  })
  userId?: string;

  @Column({
    type: 'varchar',
    length: 100,
    comment: '收件人邮箱',
  })
  toEmail: string;

  @Column({
    type: 'varchar',
    length: 200,
    comment: '邮件主题',
  })
  subject: string;

  @Column({
    type: 'varchar',
    length: 50,
    nullable: true,
    comment: '模板名称',
  })
  template?: string;

  @Column({
    type: 'enum',
    enum: ['pending', 'sent', 'failed'],
    default: 'pending',
    comment: '发送状态',
  })
  status: 'pending' | 'sent' | 'failed';

  @Column({
    type: 'text',
    nullable: true,
    comment: '错误信息',
  })
  error?: string;

  @Column({
    type: 'timestamp',
    nullable: true,
    comment: '发送时间',
  })
  sentAt?: Date;
}
